/*
 * CharSequence.java
 *
 * Copyright 2003 Sergio Anibal de Carvalho Junior
 *
 * This file is part of NeoBio.
 *
 * NeoBio is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * NeoBio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with NeoBio;
 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Proper attribution of the author as the source of the software would be appreciated.
 *
 * Sergio Anibal de Carvalho Junior		mailto:sergioanibaljr@users.sourceforge.net
 * Department of Computer Science		http://www.dcs.kcl.ac.uk
 * King's College London, UK			http://www.kcl.ac.uk
 *
 * Please visit http://neobio.sourceforge.net
 *
 * This project was supervised by Professor Maxime Crochemore.
 *
 */

package neobio.alignment;

import java.io.IOException;

public class CharSequence {

	protected String sequence;

	/**
	 * Creates a new instance of a <CODE>CharSequence</CODE>, loading the
	 * sequence data from the <CODE>Reader</CODE> input stream.
	 * 
	 * @param seq
	 *            source of characters for this sequence
	 * @throws IOException
	 *             if an I/O exception occurs when reading the input
	 * @throws InvalidSequenceException
	 *             if the input does not contain a valid sequence
	 */
	public CharSequence(String seq) throws IOException,
			InvalidSequenceException {
		this.sequence = seq;
	}

	/**
	 * Returns the number of characters of this sequence.
	 * 
	 * @return int number of characters of this sequence
	 */
	public int length() {
		return this.sequence.length();
	}

	/**
	 * Returns the character at a given position. For the client, the first
	 * character is at position 1, while the last character is at position
	 * <CODE>length()</CODE>. This is convinient for sequence alignment
	 * algorithms based on a classic dynamic programming matrix since the
	 * sequences usually start at row/column 1. This method does not check
	 * boundaries, therefore an <CODE>ArrayIndexOutOfBoundsException</CODE> may
	 * be raised if <CODE>pos</CODE> is out of bounds.
	 * 
	 * @param pos
	 *            position of character (from 1 to <CODE>length()</CODE>
	 *            inclusive)
	 * @return the character
	 */
	public char charAt(int pos) {
		// convert from one-based to zero-based index
		return this.sequence.charAt(pos - 1);
	}

	/**
	 * Returns a string representation of the sequence.
	 * 
	 * @return a string representation of the sequence
	 */

	public String toString() {
		return this.sequence;
	}

}